package top.xin1901.j2ecd.service.impl;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import top.xin1901.j2ecd.beans.Type;
import top.xin1901.j2ecd.dao.TypeDao;
import top.xin1901.j2ecd.service.TypeService;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * @author HeYunjia
 */

@Service
public class TypeServiceImpl implements TypeService {

    @Resource
    private TypeDao typeDao;

    @Override
    public Type insertOne(Type type) {

        type.setGmtCreate(new Date());
        type.setGmtModified(new Date());

        return typeDao.insert(type) == 1 ? type : null;
    }

    @Override
    public Integer deleteOne(Long typeId) {
        return typeDao.deleteByPrimaryKey(typeId);
    }

    @Override
    public Type updateOne(Type type) {

        type.setGmtModified(new Date());

        return typeDao.updateByPrimaryKey(type) == 1 ? type : null;
    }

    @Override
    public List<Type> selectAll() {
        return typeDao.selectAll();
    }

    @Override
    public Type selectOne(Long typeId) {
        if (typeId == null) return null;
        return typeDao.selectByPrimaryKey(typeId);
    }
}
